//
//  LGWelcomeViewController.swift
//  LGWeibo
//
//  Created by 李更 on 8/13/16.
//  Copyright © 2016 itcast. All rights reserved.
//

import UIKit
import SDWebImage

class LGWelcomeViewController: UIViewController {
    
    
    
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidDisappear(animated)
        //更改头像顶部约束
        headimageView.snp_updateConstraints { (make) in
            make.top.equalTo(self.view).offset(100)
        }
       
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: {
            self.view.layoutIfNeeded()
            }) { (_) in
                UIView.animateWithDuration(0.05, animations: {
                    self.messageLable.alpha = 1
                    }, completion: { (_) in
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSWITCHROOTVCNOTIFICTION, object: nil)
                        
                })
        }
        
    }
    

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()

    }
    
    func setupUI(){
               //添加控件
        view.addSubview(bgImageView)
        view.addSubview(headimageView)
        view.addSubview(messageLable)
        
        //设置约束
        bgImageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
        }
        headimageView.snp_makeConstraints { (make) in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(200)
        }
        messageLable.snp_makeConstraints { (make) in
            make.top.equalTo(headimageView.snp_bottom).offset(10)
            make.centerX.equalTo(view)
        }
        
    }
    
    //懒加载控件
    private lazy var bgImageView : UIImageView = UIImageView(imageName: "ad_background")
    private lazy var headimageView : UIImageView = {
        let img = UIImageView(imageName: "avatar_default_big")
//        img.sd_setImageWithURL(NSURL(string:(LGUserAccountViewModel.sharedTools.userAccount?.avatar_large)!), placeholderImage: UIImage(named: "avatar_default_big"))
        img.lg_setImageWithString(LGUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImage: "avatar_default_big")
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        return img
     }()
    private lazy var messageLable : UILabel = {
        let messageLable = UILabel()
        messageLable.font = UIFont.systemFontOfSize(18)
        messageLable.text = "欢迎回来"
        messageLable.textColor = UIColor.darkGrayColor()
        messageLable.textAlignment = .Center
        messageLable.alpha = 0
        
        return messageLable
    }()
    
    
    
  }
